#include "ThreadPool.hpp"
#include "Task.hpp"
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <unistd.h>
#include "Log.hpp"



int main()
{
    //logMessage(NORMAL, "%s %d %c %f\n", "这是一条日志信息", 1234, 'c', 3.14);

    srand((uint64_t)time(nullptr) ^ getpid() ^ 0x123124551);
    //ThreadPool<Task>* tp = new ThreadPool<Task>();
    //ThreadPool<Task>* tp = ThreadPool<Task>::getThreadPool(5);
    //tp->run();
    ThreadPool<Task>::getThreadPool()->run();

    while (true)
    {
        //生产的过程，制作任务的时候，需要花费时间
        int x = rand() % 100 + 1;
        usleep(3425);
        int y = rand() % 50 + 1;

        Task t(x, y, [](int x, int y)->int {return x + y;});
        //std::cout << "制作任务完成: " << x << " + " << y << " =?" << std::endl;
        logMessage(DEBUG, "制作任务完成: %d + %d = ?", x, y);

        //推送任务到线程池中
        //tp->pushTask(t);
        ThreadPool<Task>::getThreadPool()->pushTask(t);
        sleep(1);
    }

    return 0;
}
